/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.nsgf.library.ui.adapter;

import android.content.Context;
import android.content.Intent;

import androidx.recyclerview.widget.RecyclerView;

import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;
import com.nsgf.library.R;
import com.nsgf.library.data.bean.ClockInBean;
import com.nsgf.library.data.bean.VideoListBean;
import com.nsgf.library.databinding.ItemHomeCheckWorkAttendanceListBinding;
import com.nsgf.library.ui.page.video.VideoInfoActivity;
import com.nsgf.skjz.utils.StringUtil;

/**
 * Create by GC at 24/12/19
 */
public class CheckWorkAttendanceListAdapter extends SimpleDataBindingAdapter<VideoListBean.ListBean, ItemHomeCheckWorkAttendanceListBinding> {

    public CheckWorkAttendanceListAdapter(Context context) {
        super(context, R.layout.item_home_check_work_attendance_list, DiffUtils.getInstance().getClockInInfoLateItemCallback());

    }

    @Override
    protected void onBindItem(ItemHomeCheckWorkAttendanceListBinding binding, VideoListBean.ListBean item, RecyclerView.ViewHolder holder) {
        binding.setVm(item);

        if (!StringUtil.isEmpty(item.getDeviceName())) {
            if (!StringUtil.isEmpty(item.getCoordinates())) {
                String[] points = item.getCoordinates().split(",");
                if (points.length == 2) {
                    setOnItemClickListener((viewId, item1, position) ->
                            mContext.startActivity(new Intent()
                                    .putExtra("callingMode", item1.getCallingMode())
                                    .putExtra("deviceCode", item1.getDeviceCode())
                                    .putExtra("channelId", item1.getChannelId())
                                    .putExtra("deviceName", item1.getDeviceName())
                                    .putExtra("lat", points[1])
                                    .putExtra("lon", points[0])
                                    .setClass(mContext, VideoInfoActivity.class)));
                } else {

                    setOnItemClickListener((viewId, item1, position) ->
                            mContext.startActivity(new Intent()
                                    .putExtra("callingMode", item1.getCallingMode())
                                    .putExtra("deviceCode", item1.getDeviceCode())
                                    .putExtra("channelId", item1.getChannelId())
                                    .putExtra("deviceName", item1.getDeviceName())
                                    .putExtra("lat", "")
                                    .putExtra("lon", "")
                                    .setClass(mContext, VideoInfoActivity.class)));
                }
            }

        }
    }
}
